import { request, handleError } from "./request";
const BASE_URL = "http://127.0.0.1:8088";
/**
 * 管理员登录
 * @param {String} account 账号
 * @param {String} password 密码
 * @returns {Object} res 返回结果
 */
export const doLogin = async (account, password) => {
  try {
    const param = new URLSearchParams();
    param.append("account", account);
    param.append("password", password);

    const res = await request.post(BASE_URL + "/user/login", param);
    return res;
  } catch (err) {
    handleError(err);
  }
};
export const updataeUser = async (val) => {
  try {
    // const param = new URLSearchParams();
    // param.append("account", account);
    // param.append("password", password);
    let param = {
      account: val.account,
      password: val.password,
      email: val.email,
      sex: val.sex,
    };

    const res = await request.post(BASE_URL + "/user/updateUserInfo ", param);
    return res;
  } catch (err) {
    handleError(err);
  }
};
export const createUserFormFn = async (val) => {
  try {
    // const param = new URLSearchParams();
    // param.append("account", account);
    // param.append("password", password);
    let param = {
      account: val.account,
      password: val.password,
      email: val.email,
      sex: val.sex,
    };

    const res = await request.post(BASE_URL + "/user/addUser", param);
    return res;
  } catch (err) {
    handleError(err);
  }
};
